package org.isthisjava.client;

import org.isthisjava.service.ExampleService;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class HelloWorldController extends SimpleFormController {

	private ExampleService exampleService = null;

	public HelloWorldController(ExampleService exampleService) {
		super();
		this.exampleService = exampleService;
		setCommandClass(HelloWorldCommand.class);
		setCommandName("command");
		setFormView("/form");
		setSuccessView("/succes");
	}

	@Override
	protected void doSubmitAction(Object command) throws Exception {
		HelloWorldCommand helloWorldCommand = (HelloWorldCommand) command;
		String answer = exampleService.say();
		helloWorldCommand.setAnswer(answer);
	}
}
